﻿using System;
using System.Collections.Generic;
using System.Text;

using MicroMq.Core; 

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class MicroMqExtensions
    {

        public static IServiceCollection AddMicroMq(this IServiceCollection services)
        {
            services.AddTransient<IConfigureOptions<MicroMqOptions>>(serviceProvider => new ConfigureOptions<MicroMqOptions>(option =>
            {
                option.Url = serviceProvider.GetRequiredService<IConfiguration>()["MicroMq"];
            }));
            services.AddSingleton<MicroMqFactory>();
            services.AddSingleton(p => p.GetService<MicroMqFactory>().GetProducer());
            return services;
        }

        public static IServiceCollection AddMicroMq(this IServiceCollection services, Action<MicroMqOptions> options)
        {
            return AddMicroMq(services).Configure(options);
        }


    }
}
